package com.itqf.controller;

import com.itqf.entity.Goods;
import com.itqf.entity.PageBean;
import com.itqf.service.GoodsService;
import com.itqf.service.impl.GoodsServiceImpl;
import com.itqf.utils.Constants;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/goods")
public class GoodsController extends BaseServlet {

   public String show(HttpServletRequest req, HttpServletResponse resp) throws IOException, SQLException {
       int tid = Integer.parseInt(req.getParameter("tid"));
       int pageSize = 8;
       String currentPage = req.getParameter("currentPage");
       int page = 1;
       if(currentPage!=null){
           page = Integer.parseInt(currentPage);
       }
       GoodsService goodsService = new GoodsServiceImpl();
       PageBean<Goods> pageBean = goodsService.findPage(tid,page,pageSize);
       req.setAttribute("pageBean",pageBean);
       return Constants.FOW+"/goodsList.jsp";
   }
    public String detail(HttpServletRequest req, HttpServletResponse resp) throws  SQLException {
       int gid = Integer.parseInt(req.getParameter("gid"));
       GoodsService goodsService = new GoodsServiceImpl();
       Goods goods = goodsService.findGoodsByGid(gid);
       req.setAttribute("goods",goods);
        return Constants.FOW+"/goodsDetail.jsp";
    }
}
